<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: order_details_cart.php 272 2013-09-23 08:47:27Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 272 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-23 08:47:27 +0000 (Mon, 23 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

$module_smarty = new Smarty();
$module_smarty->assign('tpl_path', 'templates/'.CURRENT_TEMPLATE.'/');

require_once (DIR_FS_INC.'inc.check_stock.php');
require_once (DIR_FS_INC.'inc.get_products_stock.php');
require_once (DIR_FS_INC.'inc.remove_non_numeric.php');
require_once (DIR_FS_INC.'inc.get_attributes_model.php');
require_once (DIR_FS_INC.'inc.get_clean_id.php');
require_once (DIR_FS_INC.'inc.get_product_id.php');
require_once (DIR_FS_INC.'inc.get_shippingtime_functions.php');

$module_content = array();
$any_out_of_stock = '';
$mark_stock = '';
$t_price = '';
$p_price ='';
$max_shipping_time_ranking = 0;

for ($i = 0, $n = sizeof($products); $i < $n; $i ++) {
	if (STOCK_CHECK == 'true') {
		$mark_stock = check_stock($products[$i]['id'], $products[$i]['quantity']);
		if ($mark_stock)
			$_SESSION['any_out_of_stock'] = 1;
	}
	$max_shipping_time_ranking = max($max_shipping_time_ranking, get_shippingtime_rank('name', $products[$i]['shipping_time']));

	$attributes_exist = ((isset ($products[$i]['attributes'])) ? true : false);
	$p_price = ($attributes_exist ? $price->format($products[$i]['price']*$products[$i]['quantity'], true) : $price->format($products[$i]['single_price'] * $products[$i]['quantity'], true));
	
	if($attributes_exist)
		$t_price = $price->format(($products[$i]['single_price']*$products[$i]['quantity'])+($_SESSION['cart']->attributes_price($products[$i]['id'])*$products[$i]['quantity']), true);
	
	$module_content[$i] = array('PRODUCTS_NAME' => $products[$i]['name'].$mark_stock,
								'PRODUCTS_ID' => $products[$i]['id'],
								'PRODUCTS_ID_CLEAN' => get_clean_id($products[$i]['id']),
								'PRODUCTS_QTY' => draw_input_field('cart_quantity[]', $products[$i]['quantity'], 'size="3" id="qty_'.$products[$i]['id'].'" class="products_qty"').draw_hidden_field('products_id[]', $products[$i]['id']).draw_hidden_field('old_qty[]', $products[$i]['quantity']),
								'QTY' => $products[$i]['quantity'],
								'PRODUCTS_MODEL' => $products[$i]['model'],
								'PRODUCTS_SHIPPING_TIME' => (ACTIVATE_SHIPPING_STATUS == 'true' ? $products[$i]['shipping_time']:''),
								'PRODUCTS_TAX' => number_format($products[$i]['tax_class_id'], TAX_DECIMAL_PLACES),
								'PRODUCTS_IMAGE' => $products[$i]['image'],
								'IMAGE_ALT' => $products[$i]['name'],
								'DEL_LINK' => href_link(FILENAME_SHOPPING_CART, get_all_get_params().'del='.$products[$i]['id']),
								'EDIT_LINK' => href_link(FILENAME_PRODUCT_INFO, get_all_get_params().'products_id='.get_product_id($products[$i]['id'])).'?edit='.$products[$i]['id'],
								'DUPL_LINK' => href_link(FILENAME_PRODUCT_INFO, get_all_get_params().'products_id='.get_product_id($products[$i]['id'])).'?dupl='.$products[$i]['id'],
								'PLUS_LINK' => href_link(FILENAME_SHOPPING_CART, get_all_get_params().'plus='.$products[$i]['id']),
								'MINUS_LINK' => href_link(FILENAME_SHOPPING_CART, get_all_get_params().'minus='.$products[$i]['id']),
								'PRODUCTS_LINK' => href_link(FILENAME_PRODUCT_INFO, product_link($products[$i]['id'], $products[$i]['name'])),
								'PRODUCTS_SINGLE_PRICE' => $price->format($products[$i]['single_price'], true),
								'PRODUCTS_PRICE' => $p_price,
								'PRODUCTS_PRICE_TOTAL' => $t_price,
								'ATTRIBUTES' => '');
								
	if ($attributes_exist == 1) {
		$count_attr_value = '';
		$count_attr = '';
		$ii = 0;
		$a_price = '';
		reset($products[$i]['attributes']);
		while (list ($option, $value) = each($products[$i]['attributes'])) { $ii++;
  			if (ATTRIBUTE_STOCK_CHECK == 'true' && STOCK_CHECK == 'true') {
  				$attribute_stock_check = check_stock_attributes($products[$i][$option]['products_attributes_id'], $products[$i]['quantity']);
  				if ($attribute_stock_check)
  					$_SESSION['any_out_of_stock'] = 1;
  			}
  			
  			if($products[$i][$option]['products_options_name'] != 'Downloads') {
  				$a_s_price = $price->format($products[$i][$option]['options_values_price'], true, $products[$i]['tax_class_id']);
  				$a_price = $price->format($products[$i][$option]['options_values_price'] * $products[$i]['quantity'], true, $products[$i]['tax_class_id']);
  			}
  				
  			
  			$module_content[$i]['ATTRIBUTES'][] = array('ID' => $products[$i][$option]['products_attributes_id'],
  														'MODEL' => get_attributes_model(get_prid($products[$i]['id']), $products[$i][$option]['products_options_values_name'],$products[$i][$option]['products_options_name']),
  														'NAME' => $products[$i][$option]['products_options_name'],
  														'ATTR_QTY' => ($products[$i][$option]['products_options_name'] != 'Downloads')? $products[$i]['quantity'].'x':'',
  														'PRICE' => $a_price,
  														'SINGLE_PRICE' => $a_s_price,
  														'MODEL' => $products[$i][$option]['products_attributes_model'],
  														'ATTR_ID' => get_prid($products[$i]['id']).'_'.$option.'_'.$value,
  														'PREFIX' =>  ($products[$i][$option]['products_options_name'] != 'Downloads')?$products[$i][$option]['price_prefix']:'',
  														'VALUE_NAME' => $products[$i][$option]['products_options_values_name'].$attribute_stock_check);
  			$count_attr_value += $products[$i][$option]['options_values_price'];
  			$count_attr = $ii;
  		}
		$module_content[$i]['PRODUCTS_ATTR_COUNT'] = $count_attr+2;
	}
}

$ot_total = $price->_ext->get_total_values();

$total_content = '';
$total = $_SESSION['cart']->show_total();
$total_netto = $_SESSION['cart']->show_total();

if($_SESSION['customers_status']['customers_status_show_price'] == '1')
  $total_content .= '<div class="ot_subtotal">'.SUB_TITLE_SUB_TOTAL.' '.$price->format($ot_total['ot_sum_products']['price']+$price->_ext->sum_tax($ot_total['ot_sum_products']['tax']), true).'</div>';
else
	$total_content .= '<div class="ot_subtotal">'.NOT_ALLOWED_TO_SEE_PRICES.'</div>';

$ot_discounts_content = '';
foreach($ot_total['ot_discounts'] as $k => $v) {
  if ($k != '_all') {
    if ($ot_discounts_content != '') $ot_discounts_content .= '</br>';
    $ot_discounts_content 
      .= number_format($v['rate'],1,',','.').$v['name'] . ': -'
        . $price->format($v['price']+$price->_ext->sum_tax($v['tax']), true);
  }
}
$total_content .= '<div class="ot_discount">'.$ot_discounts_content.'</div>';

$total_content .= '<div class="ot_netto">netto: '.$price->format($ot_total['ot_sum']['price'], true).'</div>';

$ot_taxes_content = '';
foreach($ot_total['ot_taxes'] as $k => $v) {
  if ($k != '_all') {
    if ($ot_taxes_content != '') $ot_taxes_content .= '</br>';
    $ot_taxes_content .= $v['name'] . ': ' . $price->format($v['rate'], true);
  }
}
$total_content .= '<div class="ot_tax">'.$ot_taxes_content.'</div>';

if(SHOW_SHIPPING == 'true')
	$module_smarty->assign('SHIPPING_INFO', $main->getShippingLink());

if(SHOW_SHIPPING_PREVIEW == 'true')
	include(DIR_WS_MODULES.'order_details_shipping_preview.php');

if(CROSSSELLING_CART == 'true' && sizeof($products) > 0)
	include(DIR_WS_MODULES.'order_details_crossselling.php');

$module_smarty->assign('SHIPPING_TIME', get_shippingtime_name('ranking', $max_shipping_time_ranking));

$total_content .= '<div class="ot_total">'.SUB_TITLE_TOTAL.' '.$price->format($ot_total['ot_sum']['full'], true).'</div>';

$module_smarty->assign('TOTAL_CONTENT', $total_content);
$module_smarty->assign('language', $_SESSION['language']);
$module_smarty->assign('module_content', $module_content);

$module_smarty->caching = false;
$module = $module_smarty->fetch(CURRENT_TEMPLATE.'/module/order_details.html');

$smarty->assign('MODULE_order_details', $module);